package com.zy.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.common.result.Result;
import com.zy.model.system.SysOperLog;
import com.zy.model.vo.SysOperLogQueryVo;
import com.zy.system.mapper.OperLogMapper;
import com.zy.system.service.SysOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @Author Gong
 * @Description
 * @dATE 2023/6/12 19:44
 **/
@Service
public class OperLogServiceImpl implements SysOperLogService {
    @Autowired
    private OperLogMapper operLogMapper;
    @Override
    public void saveSysLog(SysOperLog sysOperLog) {
        operLogMapper.insert(sysOperLog);
    }

    @Override
    public IPage<SysOperLog> selectPage(Long page, Long limit, SysOperLogQueryVo sysOperLogQueryVo) {
        Page<SysOperLog> pageParams = new Page<>(page,limit);
        //获取条件值
        String title = sysOperLogQueryVo.getTitle();
        String operName = sysOperLogQueryVo.getOperName( );
        String createTimeBegin = sysOperLogQueryVo.getCreateTimeBegin();
        String createTimeEnd = sysOperLogQueryVo.getCreateTimeEnd( );
        //封装参数
        QueryWrapper<SysOperLog> wrapper = new QueryWrapper<>( );
        if(!StringUtils.isEmpty(title)) {
            wrapper.like("title", title);
        }
        if(!StringUtils.isEmpty(operName)) {
            wrapper.like("oper_name", operName);
        }
        if(!StringUtils.isEmpty(createTimeBegin)) {
            wrapper.gt("create_time", createTimeBegin);
        }
        if(!StringUtils.isEmpty(createTimeEnd)) {
            wrapper.lt("create_time", createTimeEnd);
        }

        IPage<SysOperLog> sysOperLogPage = operLogMapper.selectPage(pageParams, wrapper);
        return sysOperLogPage;
    }
}
